/**
 * Mockcat Server
 * @author Wangtd
 */
const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');

const config = require('./config.js');
const mocker = require('./lib/mocker.js');
const router = require('./lib/router.js');

var app = express();

app.use('/app', express.static(path.join(__dirname, 'app')));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json({ type: 'application/json', limit: '5mb' }));
app.use('/mock', router);
app.use('/', mocker.listen(config.mockDir));

//set port & ipv4 address
http.createServer(app).listen(config.port, '0.0.0.0', function(error) {
    if (error) {
        console.error(error);
    } else {
        console.log('Mockcat server is running at http://localhost:%d/', config.port);
    }
});
